package com.zfl.config;

import com.zfl.filter.RolePermissionFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {


    @Autowired
    private RolePermissionFilter rolePermissionFilter; // 注入 Spring 管理的过滤器


    @Bean
    public FilterRegistrationBean<RolePermissionFilter> registerRolePermissionFilter() {
        System.out.println("角色权限过滤配置");
        FilterRegistrationBean<RolePermissionFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(rolePermissionFilter);
        registrationBean.addUrlPatterns("/*"); // 拦截所有请求
        registrationBean.setOrder(1); // 过滤器执行顺序（数值越小越先执行）
        return registrationBean;
    }
}
